<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增自有账户</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<form id="friBaseInfo_form">
		<div class="fieldset1 tabel_col tabel_col_1 clearFix" >
			<!-- <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder"> -->
			<c:set var="read" value=""/>
			<c:if test="${flag=='1'}"> <c:set var="read" value="readonly"/></c:if>
			<div class="fieldBox col_50">
				<div class="label">账号：</div>
				<div class="field">
					<input ${read} name="accNum" id="accNum" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:100}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">户名：</div>
				<div class="field">
					<input ${read} name="accNm" id="accNm" type="text"  class="ui-textbox" value="" validate="{required:true, maxlength:100}">
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">账户类型：</div>
				<div class="field">
					<input type="text" name="accTypCdNm"  id="accTypCdNm" value="我司自有账户" readonly class="ui-textbox">
					
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">可投放款项：</div>
				
				<div class="field">
				
							<input type="text"  name="purpCdsNm" id="purpCdsNm"  class="ui-textbox" validate="{required:true, maxlength:100}">
							<input type="hidden" name="purpCds" id="purpCds" data-ligerid="purpCdsNm" value="" >
				
				<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">状态：</div>
				
				<div class="field">
				
					<c:if test="${flag=='1'}">
						<input type="text" name="accStsCdNm"  id="accStsCdNm" value="" readonly class="ui-textbox">
					</c:if>
					<c:if test="${flag!='1'}">
						 <select name="accStsCd" id="accStsCd" data-value="${accStsCd}" ligerui="width: 210">
                    		<c:forEach items="${accStsCdList }" var="im">
                     			<option value="${im.key }">${im.value }</option>
                        	</c:forEach>
                    	</select>
						
					</c:if>
					
				</div>
			</div>
			<c:if test="${not empty bankAccInfo.fundRasInsIdNm}">
			<div class="fieldBox col_50"><!--add 金融机构显示 by gengchunlan 20180302  -->
				<div class="label">金融机构：</div>
				<div class="field">
					${bankAccInfo.fundRasInsIdNm}
				</div>
			</div>
			</c:if>
			<c:if test="${not empty bankAccInfo.accTypCd and bankAccInfo.accTypCd != '6'}">
			<div class="fieldBox col_50" >
				<div class="label">支付表所属机构：</div>
				
				<div class="field">
					<input type="radio" name="bizFlag"  value="1"
					<c:if test="${flag=='1'}">disabled</c:if>
					<c:if test="${bankAccInfo.bizFlag!='0'}"> checked </c:if>
					>狮桥
					<input type="radio" name="bizFlag"  value="0"
					<c:if test="${flag=='1'}">disabled</c:if>
					<c:if test="${bankAccInfo.bizFlag=='0'}"> checked </c:if>
					>机构
				</div>
			</div>
			</c:if>
			<div class="fieldBox col_50" >
			<font color="red">可投放款项不含工行拒单费用项</font>
			</div>
			<!-- hide data -->
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					<input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
					<input type="text" id="accTypCd" name="accTypCd" value="${accTypCd}"/>
					<!--add pre账户用途  by gengchunlan 20180227  -->
					<input type="text" id="accTypCdPre" name="accTypCdPre" value="${accTypCdPre}"/> 
				</div>
			</div>
		<!-- add 非资管pre-abs账号不可投放限制 by gengchunlan -->
		<div id="limitDiv" style="display:none">
			<div class="caption">
					<span class="title">非资管pre-abs账号不可投放限制</span>
			</div>
			<div class="fieldBox col_50" >
				<div class="label">不可投放项目类型</div>
				<div class="field">
						<input type="text"  name="forbidProjectTypeNm" id="forbidProjectTypeNm"  class="ui-textbox" validate="{required:false, maxlength:100}">
						<input type="hidden" name="forbidProjectType" id="forbidProjectType" data-ligerid="forbidProjectTypeNm" value="" >
				</div>
			</div>
			<div class="fieldBox col_50" >
				<div class="label">不可投放地区</div>
				<div class="field">
				        <c:if test="${flag!='1'}">（<input type="checkbox" onchange="selectAll(this);"/>全选）</c:if>
						<input type="text"   name="forbidAreaNm" id="forbidAreaNm"  class="ui-textbox" validate="{required:false, maxlength:100}">
						<input type="hidden" name="forbidArea" id="forbidArea" data-ligerid="forbidAreaNm" value="" > 
						<!-- <select name="forbidArea" id="forbidArea">
							<option value="">请选择</option>
							<option value="XJ">新疆</option>
						</select> -->
				</div>
			</div>
			<div class="fieldBox col_50" >
				<div class="label">新车LTV限制</div>
				<div class="field">
					<input ${read} name="newCarLTV" id="newCarLTV" type="text" class="ui-textbox" value="${bankAccInfo.newCarLTV}" validate="{number:true, maxlength:60}">
				</div>
			</div>
			<div class="fieldBox col_50" >
				<div class="label">二手车LTV限制</div>
				<div class="field">
					<input ${read} name="usedCarLTV" id="usedCarLTV" type="text" class="ui-textbox" value="${bankAccInfo.usedCarLTV}" validate="{number:true, maxlength:60}">
				</div>
			</div>
			<div class="fieldBox col_50" >
				<font color="red">新车或二手车LTV大于该值时不可投放</font>
			</div>
		</div>
		<!-- end by gengchunlan 非资管pre-abs账号不可投放限制  -->
		</div>
		<!--add 批次信息以及可投放事业部、顺序可修改  by gengchunlan 20180227-->
		<c:if test="${flag!='1'}"> 
		<div><span id="batchinfor"></span></div><!--pre-abs账户 有批次信息  -->
			<div id="batchCost"  class="sq-grid">
			</div>
		</c:if>
		<!-- end by gengchunlan 20180227 -->
		<div class="btnsBox">
		<c:if test="${flag!='1'}">
			<span id="cr_bsc_info_add_btn_id" class="sq-button sq-button-round" onclick="save();">保存 </span>
		</c:if>
		</div>
	</form>
	<script type="text/javascript">
	
		var a=0;
		var batchLiger=null;//批次信息 add by gengchunlan 20180228
		$(function() {
		   $("#purpCdsNm").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
           	   data: [
	                {  name: 'key', width: 100}, 
	                {  name: 'value', width: 120},
	               ],
	            url:'<%=path%>/rfbase/fribaseinfo/getpurpCd.do',
	            ajaxType :'GET',
	            slide: true,
	            valueField: 'key', textField: 'value',
	            valueFieldID: 'purpCds'
           }); 
		   initComboBox();//不可投放项目类型 不可投放地区
		   $("#friBaseInfo_form").ligerForm({
                validate: true
           });
		   initData();
		});
		
		//定义父级调用事件
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("friBaseInfo_form");
            if (!ligerForm.valid()) {
                UIUtils.alertWarning("有验证信息未通过!");
                return false; //验证不通过，不执行以下代码
            }
            //校验帐号重复
            if(checkAcc()){
            	alert("账号已经存在！");
            	return;
            }
            	
            var data = ligerForm.getData();
            var dataId = $("#dataId").val();
            var url = '<%=path%>/rfbase/fribaseinfo/addPayAcc.do';
            if(StringUtils.isNotEmpty(dataId)){
            	data["id"]= dataId;
            }
            // 用途
            var purpCds = $("#purpCds").val();
        	data["purpCds"]=purpCds;
        	//add 批次信息 by gengchunlan 20180228
        	if(batchLiger!=null){
        		data["batchJSON"] = JSON.stringify(batchLiger.getData());
        	}
        	//不可投放项目类型 forbidProjectType
        	var forbidProjectType=$('#forbidProjectType').val();
        	data["forbidProjectType"]=forbidProjectType;
        	//forbidArea不可投放地区
        	var forbidArea = $('#forbidArea').val();
        	data["forbidArea"]=forbidArea;
            /* var batchList=batchLiger.getData();
            for( var i=0;i<batchList.length;i++){
            	if(!batchList[i].buOrgCdsNm){//可投放事业部
            		$.ligerDialog.SQalert({content: "请选择可投放事业部！",SQ_type: "warning"});
            		return false;
            	}
            	if(!batchList[i].payNum){//顺序
            		$.ligerDialog.SQalert({content: "批次顺序不允许为空！",SQ_type: "warning"});
            		return false;
            	}
            } */
        	//end by gengchunlan 20180228
			AjaxUtils.ajaxPost(url, data, addCallback);
		}

		//新增回调
		function addCallback(msg) {
			if (msg.success == 1) {
				UIUtils.alertSuccess(msg.info);
				parent.grid.reload();
				/* 父级的弹出框关闭 */
				frameElement.dialog.close();
			} else {
				UIUtils.alertError(msg.info);
			}
		}
		
		
		//修改初始化数据
		function initData() {
			var dataId = $("#dataId").val();
			if(StringUtils.isNotEmpty(dataId)){
				var _url = '<%=path%>/rfbase/fribaseinfo/getAccById.do';
				AjaxUtils.ajaxGet(_url, {
					id : dataId
				}, initCallback);
			}
		}

		//初始化回调
		function initCallback(msg) {
			if (msg.success == 1) {
				setData(msg.data);//设置数据
				batchCost(msg.data); //add  可投放事业部、顺序可修改 by gengchunlan 20180227
				limitDiv(msg.data);//add 非资管pre-abs账号不可投放限制 by gengchunlan 20200219				
			} else {
				UIUtils.alertError(msg.info);
			}
		}

		//修改时候设置页面数据
		function setData(data) {
			var form = new liger.get("friBaseInfo_form");
			form.setData({
				accStsCd:data.accStsCd,
				accStsCdNm:data.accStsCdNm,
				accTypCd:data.accTypCd,
				accTypCdNm:data.accTypCdNm,
				accNum : data.accNum,
				accNm : data.accNm,
				purpCds :data.purpCds,
				purpCdsNm : data.purpCds
			});
			
		};
		function checkAcc(){
			var flag=true;
			$.ajax({
		  		type: 'post',
		  		dataType:'json',
		  		async:false, 
		  		data:{
		  			id:$("#dataId").val(),
		  			accNum:$("#accNum").val()
		  		},
		  		url: '<%=path%>/rfbase/fribaseinfo/checkAcc.do',
					success : function(msg) {
						if (msg.success == 1) {
							flag= true;
						} else {
							flag= false;
						}
					}
				});
			return flag;
		}
		//add 非资管pre-abs账号不可投放限制 by gengchunlan 20200219
		function limitDiv(data){
			var accTypCdNm = data.accTypCd;//账户用途 pre-abs账户
			var form = new liger.get("friBaseInfo_form");
			form.setData({
				forbidProjectType :data.forbidProjectType,
				forbidProjectTypeNm : data.forbidProjectType,
				forbidArea:data.forbidArea,
				forbidAreaNm:data.forbidArea
			
			});
			if(accTypCdNm =='3'){
				$("#limitDiv").show();
			}
		}//end 	
		//add 批次信息  by gengchunlan 20180227
		 var buOrgCdsNmJSON = [];
		 <c:if test="${not empty buOrgCdsNmJSON}"> buOrgCdsNmJSON = ${buOrgCdsNmJSON}; </c:if>
		//grid 
		function batchCost(data){ 
			var accTypCdNm = data.accTypCd;//账户用途
			//alert("accTypCdNm"+accTypCdNm);
			
			if(StringUtils.isNotEmpty(accTypCdNm)){
				if(accTypCdNm !='6'){
					$("#batchinfor").html("批次信息");
				}else{
					return ;
				}
			}else{
				return ;
			}
			var id=$("#dataId").val();//$("#limId").val();
			if(StringUtils.isNotEmpty(id)){
			}else{
				return ;
			}
			batchLiger = $("#batchCost").ligerGrid({
	    		url: '<%=path%>/rfbuss/fncpreabslim/initList.do?id='+id,
		    	method : 'get',	
		    	validate : {required:true},  
		        columns: [
		            { display: '批次号', name: 'batNo', minWidth: 100 ,enabledSort:true},   
		            { display: '可投放事业部', name: 'buOrgCds', minWidth: 100 ,enabledSort:true,
		            	       validate:{required:true,minlength:1},
		            	editor: 
		            	 {
		                    type: 'select',
		                    data: buOrgCdsNmJSON,
		                    isMultiSelect: true,isShowCheckBox: true,
		                    valueField: 'key',
		                    textField: 'value'
				          },
			                valueField: 'buOrgCds',
			                textField: 'buOrgCdsNm',
			                render: function (item) {
			                    return item.buOrgCdsNm;
			                }
			                //valueFieldID: 'buOrgCds'
		            },
		            { display: '额度', name: 'preLimAmt', minWidth: 100 ,
		            	render: function (rowdata, rowindex, value, column) { 
		            		
		            		var h='';
		            		if(value&&value!="null"){
		            		    h+=fmoney(value/100.00, 2);
		            		}
		                        return h;
		            		},
	            		
		            	enabledSort:true}, 
		            { display: '余额', name: 'currLimAmt', minWidth: 100 ,
		            	 render: function (rowdata, rowindex, value, column) { 
			            		var h='';
			            		if(value&&value!="null"){
			            		    h+=fmoney(value/100.00, 2);
			            		}
			                        return h;
			            		},
		            	enabledSort:true
		            }, 
		            { display: '顺序', name: 'payNum', minWidth: 100 ,enabledSort:true,
		            	 validate:{required:true,minlength:1,maxlength:100},
		            	editor: { type: 'int' }
		            },
		            //getOptColumn()
		        ],
		        pageSize:10,
		        root:'rows',
		        record:'total',
		        hideLoadButton : true,
		        width: '100%',
		        height:'100%',
		        heightDiff:-2,
		        checkbox:false,
		        hide: false, 
		        enabledEdit: true,
		        //onBeforeSubmitEdit: f_onAfterEdit,
		        rownumbers:true
		    });
			batchLiger = liger.get("batchCost");
	    } //end by gengchunlan 20180227
	  /* 	//add 验证可投放事业部与顺序是否为空   by gengchunlan 20180301
        function f_onAfterEdit(e)
         { 
            if (e.columnname == "buOrgCdsNm")
            {
                if (e.value=="") return false;
            }else{
            	alert(e.value);
            }
          return true;
        } */
	    
	    function fmoney(s, n)   
		{   
		   n = n > 0 && n <= 20 ? n : 2;   
		   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
		   var l = s.split(".")[0].split("").reverse(),   
		   r = s.split(".")[1];   
		   t = "";   
		   for(i = 0; i < l.length; i ++ )   
		   {   
		      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
		   }   
		   return t.split("").reverse().join("") + "." + r;   
		}
        function initComboBox(){
        	
        	   //不可投放项目类型
		    $("#forbidProjectTypeNm").ligerComboBox({ isShowCheckBox: true, 
		    	isMultiSelect: true,
		    	  valueField: 'key',
                  textField: 'value',
                  valueFieldID: 'forbidProjectType'                  
           });
		    liger.get("forbidProjectTypeNm").setData(${projectTypeList});
		    //$("#forbidProjectTypeNm").ligerComboBox({ disabled: true });  
		   // 不可投放地区
		    // 不可投放地区
		    $("#forbidAreaNm").ligerComboBox({ isShowCheckBox: true, 
		    	isMultiSelect: true,
           	   data: [
	                {  name: 'key', width: 100}, 
	                {  name: 'value', width: 120},
	               ],
	            slide: true,
	            valueField: 'key', textField: 'value',
	            valueFieldID: 'forbidArea'
           });
		    liger.get("forbidAreaNm").setData(${areaList});
		   
        }
        function selectAll(thisObj) {
			var areaAllStr='${areaAllStr}';
        	 console.log(thisObj.checked+areaAllStr);
             if(thisObj.checked){
            	 liger.get("forbidAreaNm").selectValue(areaAllStr);
             }else{
            	 liger.get("forbidAreaNm").selectValue("");
            	 liger.get("forbidAreaNm").clear();
             }
			
		}
	</script>
<style type="text/css">

   .l-grid-hd-row {
    background: #e7fef4 none repeat scroll 0 0;
    border-bottom: 1px solid #ececec;
    border-top: medium none;
    font-weight: bold;
    height: 28px;
    line-height: 28px;
}

    </style>
</body>
</html>